{% extends 'analysis_plugins/general_information.html' %}

{% block analysis_result_details %}

{% set metadata_list = analysis_result.get('files', []) %}
{% if metadata_list %}
    <tr>
        <th class="table-success" colspan="2">
            Results for Included Files
        </th>
    </tr>
{% endif %}
{% for metadata in metadata_list %}
    <tr>
        <td>{{ metadata['path'] }}</td>
        <td class="p-0">
            {# this should be the same as in ../routes/ajax_view.html #}
            <table class="table table-bordered table-sm mb-0">
                {% set tr_class = "" if key not in ('suid_bit', 'sgid_bit') or not value else "table-danger"%}
                <tr class={{ tr_class }}>
                <tr>
                    <td class="text-right" style="width: 25%">user / group ID</td>
                    <td class="text-left" style="width: 25%">
                        {{ metadata.uid | safe }} {{ "(" + metadata.user + ")" if metadata.user else "" }} /
                        {{ metadata.gid | safe }} {{ "(" + metadata.group + ")" if metadata.group else "" }}
                    </td>
                    <td class="text-right" style="width: 25%">creation time</td>
                    <td class="text-left" style="width: 25%">{{ metadata.creation_time | nice_unix_time | safe }}</td>
                </tr>
                <tr>
                    <td class="text-right">permissions</td>
                    <td class="text-left">
                        {{ metadata.mode | safe }} ({{ metadata.mode | octal_to_readable }})
                    </td>
                    <td class="text-right">modification time</td>
                    <td class="text-left">{{ metadata.modification_time | nice_unix_time | safe }}</td>
                </tr>
                <tr>
                    <td class="text-right">SUID / SGID / sticky bit</td>
                    {% set td_class = "table-danger" if metadata.suid_bit or metadata.sgid_bit else "" %}
                    <td class="text-left {{ td_class }}">
                        {{ metadata.suid_bit | safe }} /
                        {{ metadata.sgid_bit | safe }} /
                        {{ metadata.sticky_bit | safe }}
                    </td>
                    <td class="text-right">last access time</td>
                    <td class="text-left">{{ metadata.access_time | nice_unix_time | safe }}</td>
                </tr>
            </table>
        </td>
    </tr>
{% endfor %}

{% endblock %}


{% block ajax %}

<div id="file_results"></div>
<script>
    $(document).ready(function() {
        $('#file_results').load('/plugins/file_system_metadata/ajax/{{ firmware.uid }}');
    });
</script>

{% endblock %}
